/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.assets.shooterstates;

import edu.wpi.first.wpilibj.templates.RobotMap;
import edu.wpi.first.wpilibj.templates.assets.statemachine.State;
import edu.wpi.first.wpilibj.templates.assets.statemachine.StateMachine;
import edu.wpi.first.wpilibj.templates.commands.CommandBase;

/**
 *
 * @author Jarrod Risley
 */
public class IngestState extends State {

    /*
     * Global Class Variables
     */
    protected static IngestState INGEST = new IngestState("Ingest");
    
    private boolean oldState;
    
    // CONSTRUCTOR //
    
    
    protected IngestState(String name) {
        super(name);
    } // end IngestState Constructor
    
    protected void runFirst() {
        
        System.out.println(this + " running.");
        setNext(MoveUpOne.MOVE_UP);
        
        oldState = CommandBase.shooter.checkSwitch(2);
        
    } // end runFirst

    protected void run() {
        
        
            
        CommandBase.intake.intake(RobotMap.INTAKE_FRIZBEE);
        CommandBase.shooter.ingest();

        if (CommandBase.shooter.checkSwitch(2)
                && MoveUpOne.MOVE_UP.getTimesRun() < 3)
            setFinished();
        else if (CommandBase.oi.getCoDriverController().getButtonLeftTrigger()
                && MoveUpOne.MOVE_UP.getTimesRun() >= 3) {
            
            CommandBase.intake.intake(RobotMap.INTAKE_FRIZBEE);
            CommandBase.shooter.manualBottomIndexerDrive(-0.20);
            
        } // end if-else-if
        
        if (!CommandBase.oi.getCoDriverController().getButtonLeftTrigger()){
            
            setNext(null);
            setFinished();
            
        } // end if-else-if-else
        
        System.out.println("Falling edge is: " + StateMachine.fallingEdge);
       if (StateMachine.fallingEdge == true) {
           CommandBase.shooter.incrementShooterCount();
        } // end if-else
       
       if (StateMachine.fallingEdgeLower == true) {
           CommandBase.shooter.incrementDiscCount();
       } // end if
       
    } // end run

    protected void runLast() {
        
    } // end runLast

    protected boolean isFinished() {
        return getFinished();
    } // end isFinished

    protected void end() {
        
        System.out.println(this + " ended.");
        
        CommandBase.intake.intake(RobotMap.STOP_INTAKE);
        CommandBase.shooter.stop();
        
    } // end end...lolz =P

    protected State getChainedInstance(State nextState) {
        
        INGEST.setNext(nextState);
        return INGEST;
        
    } // end getChainedInstance
    
} // end IngestState
